home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.022.AutoLaunch / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  4.6 KB  |  205 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * autolaunch event.c -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1988-1990
  7. * All Rights Reserved.
  8. *
  9. * Written by Eric Soldan.
  10. *
  11. * Developer Technical Support Apple II Sample Code
  12. *
  13. * This file contains the code which implements the 
  14. * main event loop used by the autolaunch program.
  15. *
  16. **********************************************************************/
  17.  
  18. #include <types.h>
  19. #include <event.h>
  20. #include <font.h>
  21. #include <intmath.h>
  22. #include <lineedit.h>
  23. #include <locator.h>
  24. #include <menu.h>
  25. #include <resources.h>
  26. #include <window.h>
  27.  
  28. #include "autolaunch.h"
  29.  
  30. void            i2pstr();
  31. void            mainWindowDraw();
  32. unsigned int    validLEKey();
  33. void            updateControls();
  34. void            updateLaunchTimer();
  35. void            doNetCheck();
  36.  
  37. /**********************************************************************
  38. *
  39. * mainEvent
  40. *
  41. * This is the main part of the program.  The program cycles in this
  42. * loop until the user chooses quit.
  43. *
  44. **********************************************************************/
  45.  
  46. void    mainEvent()
  47. {
  48.     WindowPtr        wptr, keepPort;
  49.     unsigned long    id;
  50.     unsigned int    item;
  51.     char            pstr[16];
  52.  
  53.     zapLocals();
  54.  
  55.     getLaunchInfo();        /* Load the launch configuration from disk. */
  56.  
  57.     keepPort = GetPort();
  58.  
  59.     wptr = NewWindow2(NULL, NULL, NULL, NULL, 2, MainWindowID, rWindParam1);
  60.     if (!_toolErr) {
  61.         mainWindow = wptr;
  62.  
  63.         updateControls();
  64.         i2pstr(pstr, launch.timer);
  65.         fmdLESetText(mainWindow, AppTimerData, pstr);
  66.  
  67.         ShowWindow(wptr);        /* Now that everything is okay, show window. */
  68.         SelectWindow(wptr);
  69.  
  70.         doNetCheck(1);            /* Initialize the network checking. */
  71.         for (;;) {
  72.  
  73.             doNetCheck(0);
  74.             if (quitFlag) break;
  75.  
  76.             id = fakeModalDialog(&event, mainWindowDraw, handleKeys, NULL,
  77.                 fmdMenuSelect+
  78.                 fmdMenuKey+
  79.                 fmdIBeam+
  80.                 fmdDeskAcc+
  81.                 fmdUpdateAll+
  82.                 fmdMovable
  83.             );
  84.             item = id;
  85.             if (id & 0x80000000L) {        /* Hi-bit on?  It's a menu command. */
  86.                 doMenuCommand(id);
  87.                 if (quitFlag) break;    /* It was a quit menu command. */
  88.             }
  89.             else {
  90.                 switch (item) {            /* User clicked on ctl -- handle it. */
  91.                     case AppLaunch:
  92.                     quitFlag = 2;        /* User said launch, so do it. */
  93.                     break;
  94.                 }
  95.                 if (quitFlag) break;
  96.                     /* User chose quit while tabs window was up. */
  97.             }
  98.         }
  99.  
  100.         SetPort(keepPort);
  101.         CloseWindow(wptr);
  102.         mainWindow = NULL;
  103.     }
  104. }
  105.  
  106. /**********************************************************************/
  107.  
  108. pascal void        handleKeys(event)
  109. WmTaskRec*        event;
  110. {
  111.     unsigned int    c, e, m;
  112.  
  113.     c = event->message & 0xFF;
  114.     e = event->what;
  115.     m = event->modifiers & (appleKey | shiftKey | optionKey | controlKey);
  116.  
  117.     if ((e == keyDownEvt) || (e == autoKeyEvt)) {
  118.         if (validLEKey(c, m)) return;
  119.         if ((c < '0') || (c > '9')) event->what = 0;
  120.     }
  121. }
  122.  
  123. /**********************************************************************/
  124.  
  125. unsigned int    validLEKey(c, m)
  126. unsigned int    c, m;
  127. {
  128.     unsigned int    i, j;
  129.  
  130.     static char        validChrs[] = {
  131.         6,        /* Allow char-right-of-cursor delete. */
  132.         8,        /* Allow left arrow. */
  133.         9,        /* Allow tab key. */
  134.         13,        /* Allow default button. */
  135.         21,        /* Allow right arrow. */
  136.         24,        /* Allow ctrl-x to clear field. */
  137.         25,        /* Allow delete to end-of-line. */
  138.         127,    /* Allow delete. */
  139.         0        /* End of list. */
  140.     };            /* These are the valid lineEdit editing keys.  Allow them. */
  141.  
  142.     if (m & appleKey) return(1);        /* Allow command keys. */
  143.  
  144.     c &= 0xFF;                            /* Just to be sure.    */
  145.  
  146.             for (i = 0; j = validChrs[i]; i++) if (c == j) return(1);
  147.         /* If it is a valid editLine editing character, allow it. */
  148.  
  149.     return(0);
  150. }
  151.  
  152. /**********************************************************************/
  153.  
  154. void    mainWindowDraw()
  155. {
  156.     fmdStdDrawProc();
  157. }
  158.  
  159. /**********************************************************************/
  160.  
  161. void    updateControls()
  162. {
  163.     CtlRecPtr        ctlPtr;
  164.     unsigned int    *iptr, v, hilite;
  165.     char            *cptr;
  166.  
  167.     hilite = 0;
  168.  
  169.     ctlPtr = *GetCtlHandleFromID(mainWindow, AppTriggerData);
  170.     iptr = (unsigned int *)launch.triggerName;
  171.     cptr = launch.triggerName + 2;
  172.     if (!*iptr) {
  173.         ++*iptr;
  174.         *cptr = ' ';
  175.     }
  176.     ctlPtr->ctlValue = *iptr;
  177.     ctlPtr->ctlData  = (unsigned long)cptr;
  178.     if ((*iptr == 1) && (*cptr == ' ')) hilite = 255;
  179.  
  180.     ctlPtr = *GetCtlHandleFromID(mainWindow, AppTargetData);
  181.     iptr = (unsigned int *)launch.targetName;
  182.     cptr = launch.targetName + 2;
  183.     if (!*iptr) {
  184.         ++*iptr;
  185.         *cptr = ' ';
  186.     }
  187.     ctlPtr->ctlValue = *iptr;
  188.     ctlPtr->ctlData  = (unsigned long)cptr;
  189.     if ((*iptr == 1) && (*cptr == ' ')) hilite = 255;
  190.  
  191.     HiliteControl(hilite, GetCtlHandleFromID(mainWindow, AppLaunch));
  192. }
  193.  
  194. /**********************************************************************/
  195.  
  196. void    updateLaunchTimer()
  197. {
  198.     char    pstr[16];
  199.  
  200.     fmdLEGetText(mainWindow, AppTimerData, pstr);
  201.     launch.timer = pstr2i(pstr);
  202.     if (!launch.timer) launch.timer++;
  203. }
  204.  
  205.